import { apiClient } from './index'
import { mockApi } from '@/utils/mockApi'
import type { User, ApiResponse } from '@/types'

export interface LoginRequest {
  username: string
  password: string
}

export interface LoginResponse {
  access_token: string
  refresh_token: string
  token_type: string
  expires_in: number
  user: User
}

export const authApi = {
  // 用户登录
  login: async (data: LoginRequest): Promise<ApiResponse<LoginResponse>> => {
    // 使用模拟数据
    return mockApi.auth.login(data.username, data.password)
  },

  // 刷新令牌
  refresh: async (): Promise<ApiResponse<LoginResponse>> => {
    return mockApi.auth.login('admin', 'admin123')
  },

  // 用户登出
  logout: async (): Promise<ApiResponse<void>> => {
    return mockApi.auth.logout()
  },

  // 获取用户信息
  getProfile: async (): Promise<ApiResponse<User>> => {
    return mockApi.auth.getProfile()
  },

  // 获取用户权限
  getPermissions: async (): Promise<ApiResponse<any>> => {
    return {
      code: 200,
      message: 'success',
      data: {
        permissions: [
          {
            resource_type: 'database',
            resource_id: 'starrocks',
            permission: 'read'
          }
        ]
      },
      timestamp: new Date().toISOString()
    }
  },
} 